package com.bdqn.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bdqn.base.mybatis.ServiceImpl;
import com.bdqn.mapper.ShopCategoryMapper;
import com.bdqn.pojo.ShopCategory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品分类
 *
 * @author lilibo
 * @date 2021/10/09
 */
@Service
public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, ShopCategory> implements ShopCategoryService {

    /**
     * 分类
     * @return
     */
    @Override
    public List<ShopCategory> getParent() {
        List<ShopCategory> list = getList(0);
        return list;
    }

    private List<ShopCategory> getList(Integer parentId) {
        //第一次进来查询parentid为0
        List<ShopCategory> list = this.list(Wrappers.<ShopCategory>lambdaQuery()
                .eq(ShopCategory::getParentId, parentId));
        //循环第一次数据
        for (ShopCategory shopCategory : list) {
            List<ShopCategory> list1 = getList(shopCategory.getId());
            shopCategory.setShopCategoryList(list1);
        }
        return list;
    }


}
